
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:mvvmdemo/utils/apputils.dart';

class NetService{

  static NetService? _netService;
  static BuildContext? buildContext;
  Dio? _dio;

   static NetService? getNetService(){
     _netService ??= NetService();
    return _netService;
   }

   Dio? getDio(){
     _dio??=Dio();
     return _dio;

   }

  NetService() {
    getDio();
    _dio!.options.headers = {
      "version": '3.0.9',
      "Authorization": '_token',

    };
    _dio!.options.connectTimeout = 30000;
    _dio!.options.receiveTimeout = 30000;

  }

  Future<dynamic> requestHttp(String type, Map<String,dynamic> params) async {
    try{
      AppUtils.getAppUtils()!.showLoading();

      String url = "http://172.17.12.182/pos-server-home/logicexposeservice";
      var response = await _dio!.post(url, data: params);
      if (response.statusCode == 200) {
        Map result = jsonDecode(response.data) as Map;
        return result;
      }
      return null;
    }catch(e){
      e.toString();
      return null;
    }finally{
      AppUtils.getAppUtils()!.closeLoading();
    }
  }
}